package com.shujia

import scala.io.Source

object Code44NewComputer {
  def main(args: Array[String]): Unit = {
    val scoreList: List[(String, String, String)] = Source
      .fromFile("scala_code/data/score.txt")
      .getLines()
      // 将读取到的每一行数据转换成List中的元素
      .toList
      .map(
        line => {
          val column: Array[String] = line.split(",")
          (column(0), column(1), column(2))
        }
      )

    scoreList
      .map {
        case (id, course_id, score) => {
          (id, score)
        }
      }
      .groupBy {
        case (id, score) => id
      }
      .map {
        case (id, allIDList) => {
          val totalScore: Int = allIDList.map {
            case (id, score) => score.toInt
          }.sum
          (id, (1, totalScore))
        }
      }
      .map {
            // 对于case语句可以取出嵌套的数据
        case (id, (flag, totalScore)) => {
          (id, totalScore)
        }
      }.foreach(println)
  }


}
